package com.xbongbong.paas.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.PaasFormSubDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.RuleOperationEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FilterConditionsPoJo;
import com.xbongbong.paas.help.ComplexFormatHelp;
import com.xbongbong.paas.pojo.OperationsPojo;
import com.xbongbong.paas.service.BusinessRuleDynamicValueService;
import com.xbongbong.paas.service.BusinessRuleSimpleService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.util.BusinessRuleExplainUtil;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.parent.condition.ConditionFieldHandler;
import com.xbongbong.parent.condition.ConditionFieldHandlerFactory;
import com.xbongbong.parent.util.ConditionUtil;
import com.xbongbong.pro.businessrule.pojo.BusinessRuleExplainPojo;
import com.xbongbong.pro.businessrule.pojo.BusinessRuleInfoPojo;
import com.xbongbong.pro.businessrule.pojo.EqualsResultPojo;
import com.xbongbong.pro.businessrule.pojo.dto.OperationDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.domain.entity.UpdateDataValueEntity;
import com.xbongbong.pro.domain.entity.UpdateSubDataEntity;
import com.xbongbong.pro.enums.businessrule.enums.RuleValueTypeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.form.pojo.RuleTargetPojo;
import com.xbongbong.util.DataTypeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2020/10/09 10:49
 */
@Service("businessRuleSimpleService")
public class BusinessRuleSimpleServiceImpl implements BusinessRuleSimpleService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BusinessRuleSimpleServiceImpl.class);

    @Resource
    private ComplexFormatHelp complexFormatHelp;
    @Resource
    private BusinessRuleDynamicValueService businessRuleDynamicValueService;
    @Resource
    private ConditionFieldHandlerFactory conditionFieldHandlerFactory;

    @Override
    public List<UpdateDataEntity> getUpdateDataBySimple(List<PaasFormDataEntityExt> formDataList, List<? extends PaasFormSubDataEntity> subFormDataList, OperationDTO operationDTO) throws XbbException {
        if (CollectionsUtil.isEmpty(formDataList)) {
            return new ArrayList<>();
        }
        String corpid = operationDTO.getCorpid();
        List<UpdateDataEntity> updateDataList = new ArrayList<>();
        try {
            List<OperationsPojo> operationList= operationDTO.getOperations();

            if (CollectionsUtil.isNotEmpty(operationList)) {
                List<OperationsPojo> subOperationList = new ArrayList<>();
                List<OperationsPojo> mainOperationList = new ArrayList<>();
                operationList.forEach(item->{
                    String targetAttr = item.getAttr();
                    List<String> targetAttrList = ExplainUtil.getAttrByPoint(targetAttr);
                    if (targetAttrList.size() == 2) {
                        subOperationList.add(item);
                    } else {
                        mainOperationList.add(item);
                    }
                });
                BusinessRuleExplainPojo businessRuleExplainPojo = BusinessRuleExplainUtil.getSubExplainMap(operationDTO);
                // 获取主表更新数据
                updateDataList = getMainUpdateDataList(formDataList, mainOperationList, operationDTO, businessRuleExplainPojo);
                if (CollectionsUtil.isNotEmpty(subOperationList)) {
                    // 获取子表更新数据
                    Map<Long, PaasFormDataEntityExt> formDataMap = new HashMap<>(formDataList.size());
                    formDataList.forEach(item->{
                        formDataMap.put(item.getDataId(), item);
                    });
                    List<UpdateSubDataEntity> updateSubDataList = getSubUpdateDataList(subFormDataList, subOperationList, operationDTO, formDataMap, businessRuleExplainPojo);
                    // 将子表单放入主表中，主要是为了拼装数据
                    String parentAttr = ExplainUtil.getAttrByPoint(subOperationList.get(0).getAttr()).get(0);
                    // 将子表单需要更新的数据放入主表数据中
                    DataTypeUtil.setSubDataList(updateDataList, updateSubDataList, parentAttr, corpid);
                }

            }
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error("BusinessRuleSimpleServiceImpl.getUpdateDataBySimple 业务规则简易版执行出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return updateDataList;
    }


    /**
     * 获取主表更新的数据
     * @param formDataList 主表数据
     * @param mainOperationList 主表操作的字段
     * @param operationDTO 实体
     * @return java.util.List<com.xbongbong.pro.domain.entity.UpdateDataEntity>
     * @author 吴峰
     * @date 2020/9/29 15:33
     * @throws XbbException
     */
    private  List<UpdateDataEntity> getMainUpdateDataList(List<PaasFormDataEntityExt> formDataList, List<OperationsPojo> mainOperationList, OperationDTO operationDTO, BusinessRuleExplainPojo businessRuleExplainPojo) throws XbbException{
        Map<String, FieldAttrEntity> targetExplainMap = operationDTO.getTargetExplain();
        Map<String, FieldAttrEntity> thisExplainMap = operationDTO.getThisExplain();
        List<UpdateDataEntity> updateDataList = new ArrayList<>();
        long now = DateTimeUtil.getInt() + 1;
        for (PaasFormDataEntityExt item : formDataList) {
            UpdateDataEntity updateDataEntity = new UpdateDataEntity();
            List<UpdateDataValueEntity> data = new ArrayList<>();
            Iterator<OperationsPojo> iterator = mainOperationList.iterator();
            updateDataEntity.setId(item.getDataId());
            updateDataEntity.setCorpid(item.getCorpid());
            updateDataEntity.setUpdateTime(now);
            updateDataEntity.setFormId(item.getFormId());
            JSONObject resultJson = null;
            if (businessRuleExplainPojo.getIsMainAndSubForm()) {
                // 子赋主
                EqualsResultPojo equalsResultPojo = complexFormatHelp.equalsByCondition(item, item.getData(), operationDTO, null);
                List<JSONObject> resultList = equalsResultPojo.getResultList();
                if (CollectionsUtil.isNotEmpty(resultList) && equalsResultPojo.getUpdate()) {
                    resultJson = resultList.get(resultList.size()-1);
                }
            }
            while (iterator.hasNext()) {
                UpdateDataValueEntity updateDataValueEntity = new UpdateDataValueEntity();
                OperationsPojo operationsPojo = iterator.next();
                String targetAttr = operationsPojo.getAttr();
                List<String> targetAttrList = ExplainUtil.getAttrByPoint(targetAttr);
                if (targetAttrList.size() == 2) {
                    targetAttr = targetAttrList.get(0);
                }
                FieldAttrEntity targetField = targetExplainMap.get(targetAttr);
                if (Objects.isNull(targetField)) {
                    iterator.remove();
                    continue;
                }
                updateDataValueEntity.setKey(targetAttr);
                updateDataValueEntity.setEsKey(targetAttr);
                if (Objects.equals(RuleValueTypeEnum.DYNAMIC_VALUE.getType(), operationsPojo.getValueType())) {
                    String thisKey = operationsPojo.getValueAttr();
                    List<String> thisAttrList = ExplainUtil.getAttrByPoint(thisKey);
                    if (thisAttrList.size() == 2) {
                        thisKey = thisAttrList.get(0);
                    }
                    FieldAttrEntity thisField = thisExplainMap.get(thisKey);
                    if (Objects.isNull(thisField)) {
                        iterator.remove();
                        continue;
                    }
                    if (!ExplainUtil.isSubForm(targetField.getFieldType())) {
                        if (ExplainUtil.isSubForm(thisField.getFieldType())) {
                            // 子字段赋值主字段
                            if (Objects.nonNull(resultJson)) {
                                String subKey = thisAttrList.get(1);
                                thisField = businessRuleExplainPojo.getThisSubExplainMap().get(subKey);
                                if (Objects.isNull(thisField)) {
                                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.THIS_EXPLAIN_NOT_EXIST);
                                }
                                Object value = businessRuleDynamicValueService.dynamicValue(operationsPojo, thisField, targetField, item, item.getData(), operationDTO, resultJson);
                                value = DataTypeUtil.setDataType(updateDataValueEntity, value, targetField.getFieldType());
                                updateDataValueEntity.setValue(value);
                            }
                        } else {
                            // 主字段赋值主字段
                            Object value = businessRuleDynamicValueService.dynamicValue(operationsPojo, thisField, targetField, item, item.getData(), operationDTO, operationDTO.getPaasFormDataEntity().getData());
                            value = DataTypeUtil.setDataType(updateDataValueEntity, value, targetField.getFieldType());
                            updateDataValueEntity.setValue(value);
                        }
                    }
                } else {
                    if (!ExplainUtil.isSubForm(targetField.getFieldType())) {
                        Object value = businessRuleDynamicValueService.fixedValue(operationsPojo, targetField, item, item.getData(), operationDTO);
                        value = DataTypeUtil.setDataType(updateDataValueEntity, value, targetField.getFieldType());
                        updateDataValueEntity.setValue(value);
                    }
                }
                data.add(updateDataValueEntity);
            }
            updateDataEntity.setData(data);
            updateDataList.add(updateDataEntity);
        }
        return updateDataList;
    }
    /**
     * 获取子表更新的数据
     * @param formDataList 子表数据
     * @param subOperationList 子表操作的字段
     * @param operationDTO 实体
     * @return java.util.List<com.xbongbong.pro.domain.entity.UpdateDataEntity>
     * @author 吴峰
     * @date 2020/9/29 15:33
     * @throws XbbException
     */
    private List<UpdateSubDataEntity> getSubUpdateDataList(List<? extends PaasFormSubDataEntity> formDataList, List<OperationsPojo> subOperationList,
                                                           OperationDTO operationDTO, Map<Long, PaasFormDataEntityExt> formDataMap, BusinessRuleExplainPojo businessRuleExplainPojo) throws XbbException {
        List<UpdateSubDataEntity> subDataList = new ArrayList<>();
        String corpid = operationDTO.getCorpid();
        // 目标表单
        Map<String, FieldAttrEntity> targetExplainMap = operationDTO.getTargetExplain();
        Map<String, FieldAttrEntity> targetSubExplainMap = businessRuleExplainPojo.getTargetSubExplainMap();
        // 本表单
        Map<String, FieldAttrEntity> thisExplainMap = operationDTO.getThisExplain();
        Map<String, FieldAttrEntity> thisSubExplainMap = businessRuleExplainPojo.getThisSubExplainMap();

        // 子表单和主表单的对应
        Map<Long, List<PaasFormSubDataEntity>> subFormDataMap = new HashMap<>();
        formDataList.forEach(item -> {
            subFormDataMap.computeIfAbsent(item.getDataId(), v -> new ArrayList<>()).add(item);
        });

        PaasFormDataEntity thisFormData = operationDTO.getPaasFormDataEntity();
        RuleTargetPojo ruleTargetPojo = operationDTO.getTarget();

        BusinessRuleInfoPojo businessRuleInfoPojo = new BusinessRuleInfoPojo(corpid, operationDTO.getThisExplain(), operationDTO.getTargetExplain(), ruleTargetPojo, operationDTO.getFormId(), operationDTO.getBusinessType(), operationDTO.getSaasMark(), operationDTO.getOperationType(), operationDTO.getFormDataMap());


        Iterator<Map.Entry<Long, List<PaasFormSubDataEntity>>> iterator = subFormDataMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Long, List<PaasFormSubDataEntity>> targetFormData = iterator.next();

            Long parentId = targetFormData.getKey();
            List<PaasFormSubDataEntity> value = targetFormData.getValue();

            PaasFormDataEntityExt parentFormData = formDataMap.get(parentId);

            JSONObject thisData = thisFormData.getData();
            JSONObject thisSubData = thisFormData.getSubFormData() == null ? new JSONObject() : thisFormData.getSubFormData();

            if (businessRuleExplainPojo.getIsSubFormAndSubForm()) {
                JSONArray thisSubDataArray = thisSubData.getJSONArray(businessRuleExplainPojo.getThisKey()) == null ? new JSONArray() : thisSubData.getJSONArray(businessRuleExplainPojo.getThisKey());
                for (int i = 0; i < thisSubDataArray.size(); i++) {
                    JSONObject subDataJson = thisSubDataArray.getJSONObject(i);

                    PaasFormSubDataEntity equalFormData = null;
                    Iterator<PaasFormSubDataEntity> iter = value.iterator();
                    while (iter.hasNext()) {
                        PaasFormSubDataEntity paasFormSubDataEntity = iter.next();
                        List<FilterConditionsPoJo> subConditionsList = businessRuleExplainPojo.getSubConditionsList();

                        JSONObject data = paasFormSubDataEntity.getData();

                        boolean isEqual = false;
                        for (FilterConditionsPoJo filterConditionsPoJo : subConditionsList) {
                            if (Objects.isNull(subDataJson)) {
                                continue;
                            }
                            String targetKey = filterConditionsPoJo.getAttr();
                            if (Objects.equals(RuleValueTypeEnum.DYNAMIC_VALUE.getType(), filterConditionsPoJo.getValueType())) {
                                List<String> thisAttrList = ExplainUtil.getAttrByPoint(filterConditionsPoJo.getValueAttr());
                                FieldAttrEntity targetField;
                                if (targetKey.contains(FieldTypeEnum.SUB_FORM.getEsalias())) {
                                    targetField = targetSubExplainMap.get(ExplainUtil.getAttrByPoint(targetKey).get(1));

                                } else {
                                    targetField = targetExplainMap.get(targetKey);
                                }

                                if (thisAttrList.size() == 2) {
                                    String thisSubKey = thisAttrList.get(1);
                                    FieldAttrEntity fieldAttrEntity = thisSubExplainMap.get(thisSubKey);

                                    // 获取目标表单数据
                                    ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerFactory.getHandlerTargetFormByFieldType(targetField.getFieldType());
                                    Object targetValue = conditionFieldHandler.handlerThisFormField(parentFormData, data, targetField, fieldAttrEntity, businessRuleInfoPojo);

                                    // 获取本表单数据
                                    ConditionFieldHandler thisConditionFieldHandler = conditionFieldHandlerFactory.getHandlerTargetFormByFieldType(fieldAttrEntity.getFieldType());
                                    Object object = thisConditionFieldHandler.handlerThisFormField(thisFormData, subDataJson, fieldAttrEntity, targetField, businessRuleInfoPojo);
                                    isEqual = ConditionUtil.equals(targetValue, object, filterConditionsPoJo);
                                } else {
                                    FieldAttrEntity fieldAttrEntity = thisExplainMap.get(filterConditionsPoJo.getValueAttr());
                                    // 获取目标表单数据
                                    ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerFactory.getHandlerTargetFormByFieldType(targetField.getFieldType());
                                    Object targetValue = conditionFieldHandler.handlerThisFormField(parentFormData, data, targetField, fieldAttrEntity, businessRuleInfoPojo);

                                    // 获取本表单数据
                                    ConditionFieldHandler thisConditionFieldHandler = conditionFieldHandlerFactory.getHandlerTargetFormByFieldType(fieldAttrEntity.getFieldType());
                                    Object object = thisConditionFieldHandler.handlerThisFormField(thisFormData, thisData, fieldAttrEntity, targetField, businessRuleInfoPojo);
                                    isEqual = ConditionUtil.equals(targetValue, object, filterConditionsPoJo);
                                }

                            } else {
                                FieldAttrEntity targetField;
                                if (targetKey.contains(FieldTypeEnum.SUB_FORM.getEsalias())) {
                                    targetField = targetSubExplainMap.get(ExplainUtil.getAttrByPoint(targetKey).get(1));
                                } else {
                                    targetField = targetExplainMap.get(targetKey);
                                }
                                // 获取目标表单数据
                                ConditionFieldHandler conditionFieldHandler = conditionFieldHandlerFactory.getHandlerTargetFormByFieldType(targetField.getFieldType());
                                Object targetValue = conditionFieldHandler.handlerThisFormField(parentFormData, data, targetField, targetField, businessRuleInfoPojo);

                                // 获取当前表单的值
                                ConditionFieldHandler thisFieldCondition = conditionFieldHandlerFactory.getHandlerFixedValueByFieldType(targetField.getFieldType());
                                Object object = thisFieldCondition.handlerFixedValue(targetField, businessRuleInfoPojo, filterConditionsPoJo);
                                if (ExplainUtil.isCombo(targetField.getFieldType())) {
                                    businessRuleInfoPojo.setObject(object);
                                    Object result = thisFieldCondition.handlerThisFormField(thisFormData, thisData, targetField, targetField, businessRuleInfoPojo);
                                    isEqual = ConditionUtil.equals(targetValue, result, filterConditionsPoJo);
                                } else {
                                    isEqual = ConditionUtil.equals(targetValue, object, filterConditionsPoJo);
                                }
                            }

                            if (!isEqual) {
                                break;
                            }
                        }

                        if (isEqual) {
                            equalFormData = paasFormSubDataEntity;
                        }

                        if (!Objects.isNull(equalFormData)) {
                            UpdateSubDataEntity updateSubDataEntity = new UpdateSubDataEntity();
                            updateSubDataEntity.setSubDataId(equalFormData.getId());
                            updateSubDataEntity.setParentId(parentId);
                            updateSubDataEntity.setFormId(equalFormData.getFormId());
                            List<UpdateDataValueEntity> updateDataValueList = new ArrayList<>();
                            extracted(operationDTO, targetExplainMap, thisExplainMap, equalFormData.getData(), subOperationList, parentFormData, updateDataValueList, subDataJson);
                            if (CollectionsUtil.isNotEmpty(updateDataValueList)) {
                                updateSubDataEntity.setSubDataList(updateDataValueList);
                                subDataList.add(updateSubDataEntity);
                            }
                            break;
                        } else {
                            if (Objects.equals(operationDTO.getOperationType(), RuleOperationEnum.UPDATE_AND_INSERT.getType()) && !iter.hasNext()) {
                                UpdateSubDataEntity subDataEntity = new UpdateSubDataEntity();
                                subDataEntity.setSubDataId(null);
                                subDataEntity.setParentId(parentId);
                                subDataEntity.setFormId(parentFormData.getFormId());
                                List<UpdateDataValueEntity> insertDataValueList = new ArrayList<>();
                                extracted(operationDTO, targetExplainMap, thisExplainMap, new JSONObject(), subOperationList, parentFormData, insertDataValueList, subDataJson);
                                subDataEntity.setSubDataList(insertDataValueList);
                                subDataList.add(subDataEntity);
                            }
                        }

                    }


                }
            } else if (businessRuleExplainPojo.getIsMainAndSubForm() ||businessRuleExplainPojo.getIsSubFormAndMain()) {
                for (PaasFormSubDataEntity paasFormSubDataEntity : value) {
                    UpdateSubDataEntity updateSubDataEntity = new UpdateSubDataEntity();
                    updateSubDataEntity.setSubDataId(paasFormSubDataEntity.getId());
                    updateSubDataEntity.setParentId(parentId);
                    updateSubDataEntity.setFormId(parentFormData.getFormId());
                    List<UpdateDataValueEntity> updateDataValueList= new ArrayList<>();
                    extracted(operationDTO, targetExplainMap, thisExplainMap, paasFormSubDataEntity.getData(), subOperationList, parentFormData, updateDataValueList, operationDTO.getPaasFormDataEntity().getData());
                    if (CollectionsUtil.isNotEmpty(updateDataValueList)) {
                        updateSubDataEntity.setSubDataList(updateDataValueList);
                        subDataList.add(updateSubDataEntity);
                    }
                }

            }

        }


//        for (PaasFormSubDataEntity item : formDataList) {
//            UpdateSubDataEntity updateSubDataEntity = new UpdateSubDataEntity();
//            updateSubDataEntity.setSubDataId(item.getId());
//            updateSubDataEntity.setParentId(item.getDataId());
//            updateSubDataEntity.setFormId(item.getFormId());
//            PaasFormDataEntityExt parentFormData = formDataMap.get(item.getDataId());
//            if (businessRuleExplainPojo.getIsSubFormAndSubForm()) {
//                // 子表单内字段赋值给子表单内字段
//                // 还要和子表单的条件比较，简直刺激
//                EqualsResultPojo equalsResultPojo = complexFormatHelp.equalsByCondition(parentFormData, item.getData(), operationDTO, null);
//                List<JSONObject> resultList = equalsResultPojo.getResultList();
//                if (CollectionsUtil.isNotEmpty(resultList) && equalsResultPojo.getUpdate()) {
//                    List<UpdateDataValueEntity> updateDataValueList= new ArrayList<>();
//                    JSONObject resultJson = resultList.get(resultList.size()-1);
//                    extracted(operationDTO, targetExplainMap, thisExplainMap, item, subOperationList, parentFormData, updateDataValueList, resultJson);
//                    updateSubDataEntity.setSubDataList(updateDataValueList);
//                    subDataList.add(updateSubDataEntity);
//                } else {
//                    // 没有符合条件的数据，不用更新数据
//                    continue;
//                }
//            }
//        }
        return subDataList;
    }

    private void extracted(OperationDTO operationDTO, Map<String, FieldAttrEntity> targetExplainMap, Map<String, FieldAttrEntity> thisExplainMap, JSONObject targetData, List<OperationsPojo> subOperationList, PaasFormDataEntityExt parentFormData, List<UpdateDataValueEntity> updateDataValueList, JSONObject resultJson) throws XbbException {
        Iterator<OperationsPojo> iterator = subOperationList.iterator();
        while (iterator.hasNext()) {
            UpdateDataValueEntity updateDataValueEntity = new UpdateDataValueEntity();
            OperationsPojo operationsPojo = iterator.next();
            String targetAttr = operationsPojo.getAttr();
            List<String> targetAttrList = ExplainUtil.getAttrByPoint(targetAttr);
            if (targetAttrList.size() == 2) {
                targetAttr = targetAttrList.get(0);
            }
            FieldAttrEntity targetField = targetExplainMap.get(targetAttr);
            if (Objects.isNull(targetField) || !ExplainUtil.isSubForm(targetField.getFieldType())) {
                continue;
            }
            List<? extends FieldAttrEntity> jsonArray = targetField.getSubForm().getItems();
            Map<String, FieldAttrEntity> targetSubExplainMap = ExplainUtil.getExplainMapByList(jsonArray);
            String targetSubAttr = targetAttrList.get(1);
            FieldAttrEntity targetSubField = targetSubExplainMap.get(targetSubAttr);
            if (Objects.isNull(targetSubField)) {
                continue;
            }
            updateDataValueEntity.setKey(targetSubAttr);
            updateDataValueEntity.setEsKey(targetSubAttr);
            if (Objects.equals(RuleValueTypeEnum.DYNAMIC_VALUE.getType(), operationsPojo.getValueType())) {
                // 动态值
                String thisKey = operationsPojo.getValueAttr();
                List<String> thisAttrList = ExplainUtil.getAttrByPoint(thisKey);
                if (thisAttrList.size() == 2) {
                    thisKey = thisAttrList.get(0);
                }
                FieldAttrEntity thisField = thisExplainMap.get(thisKey);
                if (Objects.isNull(thisField)) {
                    continue;
                }
                if (ExplainUtil.isSubForm(targetField.getFieldType()) && ExplainUtil.isSubForm(thisField.getFieldType())) {
                    // 子表单内字段赋值给子表单内字段
                    if (Objects.nonNull(resultJson)) {
                        Object value = businessRuleDynamicValueService.dynamicValue(operationsPojo, thisField, targetSubField, parentFormData, targetData, operationDTO, resultJson);
                        value = DataTypeUtil.setDataType(updateDataValueEntity, value, targetField.getFieldType());
                        updateDataValueEntity.setValue(value);
                    }
                } else {
                    // 主字段赋值给子表单内字段
                    Object value = businessRuleDynamicValueService.dynamicValue(operationsPojo, thisField, targetSubField, parentFormData, targetData, operationDTO, operationDTO.getPaasFormDataEntity().getData());
                    value = DataTypeUtil.setDataType(updateDataValueEntity, value, targetField.getFieldType());
                    updateDataValueEntity.setValue(value);
                }
            } else{
                Object value = businessRuleDynamicValueService. fixedValue(operationsPojo, targetField, parentFormData, targetData, operationDTO);
                value = DataTypeUtil.setDataType(updateDataValueEntity, value, targetField.getFieldType());
                updateDataValueEntity.setValue(value);
            }
            updateDataValueList.add(updateDataValueEntity);
        }
    }


}
